package product

import (
	"net/http"

	"gitee.com/zoneaurora/shop/internal/common"
	"gitee.com/zoneaurora/shop/internal/dto"
	"gitee.com/zoneaurora/shop/internal/logic/admin/base"
	"gitee.com/zoneaurora/shop/internal/model"
	"github.com/gin-gonic/gin"
)

type ProductLogic struct {
	base.BaseLogic[model.Product]
}

func NewProductLogic() *ProductLogic {
	return &ProductLogic{
		BaseLogic: base.BaseLogic[model.Product]{
			DB: common.DB(),
		},
	}
}

func (p *ProductLogic) Options(c *gin.Context) {
  var connectCats []model.Category
  // 获取分类数据
  if err := p.DB.Find(&connectCats).Error; err != nil {
    common.JSON(c, http.StatusInternalServerError, "查询数据失败", nil)
  }
  var categories []dto.SelectItem
  for _, v := range connectCats {
    var item dto.SelectItem
    item.Label = v.Name
    item.Value = v.ID
    categories= append(categories, item)
  }

	var productModel model.Product
	common.JSON(c, http.StatusOK, "查询数据成功", gin.H{
		"model": productModel,
		"connection": gin.H{
			"CategoryID": categories,
		},
	})
}
